/*************************************************************************
 Copyright (C) Unpublished Unis Software, Inc. All rights reserved.
 Unis Software, Inc., Confidential and Proprietary.

 This software is subject to copyright protection
 under the laws of the Public of China and other countries.

 Unless otherwise explicitly stated, this software is provided
 by Unis "AS IS".
 *************************************************************************/
package com.unis.web.board;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.unis.common.ui.jqGrid.GridUIMapper;
import com.unis.common.util.WebUtil;
import com.unis.model.BaseModel;
import com.unis.model.board.BoardType;
import com.unis.service.board.boardtypeService;

/**
 * @author Alucard (email:357375084@qq.com)
 * @since 2013-03-14
 */
@Controller
@RequestMapping("/boardtype")
public class BoardTypeController {

    private boardtypeService boardtypeService;

    /****************************************
     * Insert a instace of boardtype
     ****************************************/
    @RequestMapping("/insert")
    @ResponseBody
    public Object insertBoardType(@RequestBody BoardType boardtype) throws Exception {
        boardtype.setStatmentId("BoardType.insert");
        String status = "failure";
        boardtypeService.insert(boardtype);
        status = "success";
        return status;
    }

    /****************************************
     * Update a instace of boardtype
     ****************************************/
    @RequestMapping("/update")
    @ResponseBody
    public Object update(@RequestBody BoardType boardtype) throws Exception {
        boardtype.setStatmentId("BoardType.update");
        String status = "failure";
        boardtypeService.update(boardtype);
        status = "success";
        return status;
    }

    /****************************************
     * Delete a instace of boardtype
     ****************************************/
    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(@RequestBody BoardType boardtype) throws Exception {
        boardtype.setStatmentId("BoardType.delete");
        String status = "failure";
        boardtypeService.batchDelete(boardtype);
        status = "success";
        return status;
    }

    /****************************************
     * Query instaces of boardtype
     ****************************************/
    @RequestMapping("/queryAsList")
    @ResponseBody
    public Object queryAsList(HttpServletRequest request) throws Exception {
        Map<String, Object> paramMap = WebUtil.getParamsMapFromRequest(request);
        BoardType boardtype = new BoardType();
        boardtype.setStatmentId("BoardType.queryAsList");
        BeanUtils.populate(boardtype, paramMap);
        Map<String, Object> pageMap = GridUIMapper.process(paramMap);
        BeanUtils.populate(boardtype, pageMap);
        List<BaseModel> boardtypeList = boardtypeService.queryAsList(boardtype);
        Map<String, Object> renderMap = GridUIMapper.render(boardtype, boardtypeList);
        return renderMap;
    }

    /****************************************
     * Query a instaces of boardtype
     ****************************************/
    @RequestMapping("/queryAsObject")
    @ResponseBody
    public BaseModel queryAsObject(@RequestBody BoardType boardtype) throws Exception {
        boardtype.setStatmentId("BoardType.queryAsObject");
        return boardtypeService.queryAsObject(boardtype);
    }

    @RequestMapping("/page")
    public String forword() {
        return "board/boardtypeList";
    }

    @Resource
    public void setboardtypeService(boardtypeService boardtypeService) {
        this.boardtypeService = boardtypeService;
    }
}
